﻿using System;
using Microsoft.Practices.ServiceLocation;

namespace Eswat
{
	/// <summary>
	/// Helper methods for <see cref="ServiceLocator"/>.
	/// </summary>
	public static class ServiceLocatorHelpers
	{
		/// <summary>
		/// Checks if the ServiceLocator.Current property is null.
		/// The property internally throws a <see cref="NullReferenceException"/>,
		/// so you can't simply check if ServiceLocator.Current == null
		/// </summary>
		/// <returns></returns>
		public static bool IsNull()
		{
			var serviceLocatorIsNull = false;

			try
			{
				var svcloc = ServiceLocator.Current;

				serviceLocatorIsNull = svcloc == null;
			}
			catch (NullReferenceException)
			{
				serviceLocatorIsNull = true;
			}

			return serviceLocatorIsNull;
		}
	}
}
